const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    staticUrl: app.globalData.staticUrl,
    userInfo:{},
    currentData: 0, 
    selectPerson: true,
    registerresultlists:[],
    status:["审核中","已参赛","已退赛"],
    status_id:1,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
      var statusid = options.statusid;
      
  },
  onShow:function(){
    this.setData({userInfo:app.globalData.userInfo});
    this.getdate();
  },
 
  //获取当前滑块的index
  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  
  
  
  getdate(){
    wx.showLoading({
      title: '正在加载',
    });
    console.log(this.data.userInfo);
    var that = this;
     app.getregsiterstatuslists(this.data.userInfo.player_id,this.data.status_id,function(res){
         if(res.data.data){
          that.setData({registerresultlists:res.data.data})
         }
         else{
           that.setData({registerresultlists:[]})
         }
     },function(){
       wx.hideLoading();
     });
  },

  openscorecard(e){
        var match = e.currentTarget.dataset.match;
        console.log(match);
        var that = this;
        wx.navigateTo({
          url: '../scorecon/scorecon'
           ,
           success: function(res) {
            // 通过eventChannel向被打开页面传送数据
            res.eventChannel.emit('acceptDataFromOpenerPage', { match: match,playerid:that.data.userInfo.player_id })
          }
      });
  },


  gotoentrycertificate:function(e){
    var mt_id=  e.currentTarget.dataset.mt_id;
    wx.navigateTo({
      url: '/pages/More/entrycertificate/index?mt_id='+mt_id,
    })
  },

  wxpay:function(e){

    var register_id = e.currentTarget.dataset.registerid;
    var matchname = e.currentTarget.dataset.matchname;
    if(!register_id){
      return ;
    }
    var that = this;
    app.wxpay(register_id,
      function (res) {
        console.log(res);
        wx.requestPayment({
          timeStamp: res.data.data.timeStamp,
          nonceStr: res.data.data.nonceStr,
          package: res.data.data.package,
          signType: res.data.data.signType,
          paySign: res.data.data.paySign,
          success: function (resdata) {
            /*wx.showModal({
              title: '支付成功',
              content: '',
              showCancel: false,
            })*/

            

            //支付成功跳转
            //跳转到成功页面
            var succuss = {
              message: that.data.user_info.UserTrueName + "\n" + matchname + "\n 报名支付成功",
              time: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString(),
              back: true,
              buttoninfo: "返回"
            }
            // wx.hideLoading();

            wx.navigateTo({
              url: '/pages/succuss/index?succuss=' + JSON.stringify(succuss)
            })
          },
          fail: function (resdata) {
            console.log(resdata);
            wx.showModal({
              title: '支付失败',
              content: '',
              showCancel: false,
            })
          }
        })


      },
      function () {});
  },


  downloadfile:function(e){
    var file = app.globalData.payqrcode;
    var filePath = wx.env.USER_DATA_PATH + '/pay.jpg';
    wx.downloadFile({//下载
      url: file,//服务器上的pdf地址
      success: function (res) {
        wx.saveFile({
          tempFilePath: res.tempFilePath || res.filePath,
          filePath: filePath,
          success:(fileres)=>{
            console.log(fileres);
            var filerespath = fileres.savedFilePath
            wx.previewImage({
              urls: [filerespath],
            })
          },
          fail:(faileres)=>{
            wx.showToast({
              title: faileres.errMsg,
              duration:2000,
            })
          }
        })
       
      }
    })
  },

  changedata: function (e) {

  
    var value = e.detail.value;
    
 
    this.setData({
      status_id: value
    });
    console.log(this.data.status_id);
    this.getdate();
  },
  
})